package demo;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

class Person{
    private String name;
    private int age;
    public Person(String name,int age){
        this.age=age;
        this.name=name;
    }

    @Override
    public boolean equals(Object o) {
        if(o==null)
            return false;
        if(this==o)
            return true;
        //判断是不是同种类型
        if(!(o instanceof Person))
            return false;

        Person per=(Person) o;

        if(this.age==per.age&&this.name.equals(per.name))
            return true;

        return false;
    }

    @Override
    public int hashCode() {

        return Objects.hash(name,age);
    }
}
class Student implements Comparable<Student>{
    public String name;
    public int age;
    public Student(String name,int age){
        this.name=name;
        this.age=age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        if(this.age-o.age>0) {
            return 1;
        }
        else if (this.age-o.age<0) {
            return -1;
        }
        else {
            return 0;
        }
    }
}

public class Test {

    public static void func(Object obj){
    Person person1=new Person("张三",18);
    Person person2=new Person("张三",18);
    System.out.println(person1.equals(person2));
    }

    public static void main(String[] args) {
        Student[] students=new Student[3];
        students[0]=new Student("a",18);
        students[0]=new Student("b",5);
        students[0]=new Student("c",20);
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }

    public static void main2(String[] args) {
        int[] arr={1,4,2,6,3,7,5};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void main1(String[] args) {
        Person person1=new Person("张三",18);
        Person person2=new Person("张三",18);
        System.out.println(person1.equals(person2));
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());

    }
}
